#ifndef __MESH_H__
#define __MESH_H__

#include <vector>
#include <string>
#define strtk_no_tr1_or_boost
#include "strtk/strtk.hpp"

#include "Point3Df.h"
#include "Point2Df.h"
#include "Face.h"
#include "VisiblePartFlags.h"

struct Mesh
{
public:
	std::string Name;
	int Mode;
	std::vector<Face> Faces;
	int Texture;

	Point3Df Translate, Rotate;
	Point3Df Pivot;

	bool Helmet;
	bool FollowCursor;
	float RotateFactor;

	VisiblePartFlags Part;

	Mesh(std::string name) :
		Name(name),
		Rotate(0, 0, 0)
	{
	}
		
	static char tempBuffer[1024];

	static std::string VertexToString(Point3Df v)
	{
		sprintf (tempBuffer, "%f %f %f", v.X, v.Y, v.Z);
		return tempBuffer;
	}

	static std::string VertexToString(Point2Df v)
	{
		sprintf (tempBuffer, "%f %f", v.X, v.Y);
		return tempBuffer;
	}

	static Point3Df StringToVertex3(const std::string &s)
	{
		Point3Df out;

		strtk::parse(s, ", ", out.X, out.Y, out.Z);

		return out;
	}

	static Point2Df StringToVertex2(const std::string &s)
	{
		Point2Df out;

		strtk::parse(s, ", ", out.X, out.Y);

		return out;
	}

	void Write(/*XmlWriter writer*/)
	{
		/*
		writer.WriteStartElement("Mesh");
		writer.WriteAttributeString("Name", Name);
		writer.WriteAttributeString("Mode", Mode.ToString());
		writer.WriteAttributeString("Translate", VertexToString(Translate));
		writer.WriteAttributeString("Pivot", VertexToString(Pivot));
		writer.WriteAttributeString("IsHelmet", Helmet.ToString());
		writer.WriteAttributeString("FollowCursor", FollowCursor.ToString());
		writer.WriteAttributeString("RotateFactor", RotateFactor.ToString());
		writer.WriteAttributeString("Part", Part.ToString());

		foreach (var f in Faces)
		{
			writer.WriteStartElement("Face");

			writer.WriteStartElement("Vertices");
			foreach (var v in f.Vertices)
				writer.WriteElementString("Vertex", VertexToString(v));
			writer.WriteEndElement();

			writer.WriteStartElement("TexCoords");
			foreach (var v in f.TexCoords)
				writer.WriteElementString("Coord", VertexToString(v));
			writer.WriteEndElement();

			writer.WriteStartElement("Indices");
			foreach (var v in f.Indices)
				writer.WriteElementString("Index", v.ToString());
			writer.WriteEndElement();

			writer.WriteEndElement();
		}

		writer.WriteEndElement();*/
	}
};

#endif